package com.sixth.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sixth.dao.EduTeacherDao;
import com.sixth.dao.TbCheckTeacherTbCheckTeachesDao;
import com.sixth.entity.EduTeacher;
import com.sixth.entity.TbCheckTeachers;
import com.sixth.service.TeacherlistService;
import com.sixth.until.CommonResult;
import com.sixth.until.TableResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: self-tui-education
 * @description:
 * @author: 高振杨
 * @create: 2022-04-15 19:12
 **/
@Service
public class TeacherlistServiceImpl implements TeacherlistService {
    @Autowired
    private EduTeacherDao eduTeacherDao;
    @Autowired
    private TbCheckTeacherTbCheckTeachesDao tbdao;
    @Override
        public TableResult findTeacher(Integer pageCurrent, Integer pageSize,EduTeacher teacher) {
        PageHelper.startPage(pageCurrent,pageSize);

        String name = teacher.getName();
        String mobile = teacher.getMobile();
        String status = teacher.getStatus();

        //System.out.println(name+"   "+mobile+"   "+status+"          ++++"+teacher);
        List<EduTeacher> teacherList = eduTeacherDao.findTeacherList(name,mobile,status);
        PageInfo<EduTeacher> pageInfo = new PageInfo<>(teacherList);

        return new TableResult(2000,"查询成功",pageInfo.getTotal(),pageInfo.getList());
    }

    @Override
    public CommonResult updatestatus(EduTeacher teacher) {
        String id = teacher.getId();
        String status = teacher.getStatus();
        int i=eduTeacherDao.updateStatusByid(id,status);

       // System.out.println("        "+id+"      "+status);

        if (i>0){
            return new CommonResult(200,"修改成功",null);
        }
        return new CommonResult(5000,"修改失败",null);
    }

    @Override
    public CommonResult updateTeacher(EduTeacher teacher) {

        int i = eduTeacherDao.updateByPrimaryKey(teacher);
        if (i>0){
            return new CommonResult(2000,"修改成功",null);
        }
        return new CommonResult(5000,"修改失败",null);
    }

    @Override
    public TableResult findTeacherCheck(Integer pageCurrent, Integer pageSize,EduTeacher teacher) {
        PageHelper.startPage(pageCurrent,pageSize);

        String name = teacher.getName();
        String mobile = teacher.getMobile();
        String status = teacher.getStatus();

        //System.out.println(name+"   "+mobile+"   "+status+"          ++++"+teacher);
        List<EduTeacher> teacherList = eduTeacherDao.findTeacherCheck(name,mobile,status);

       // System.out.println(teacherList);

        PageInfo<EduTeacher> pageInfo = new PageInfo<>(teacherList);

        return new TableResult(2000,"查询成功",pageInfo.getTotal(),pageInfo.getList());
    }

    @Override
    public CommonResult changeTeacherCheck(TbCheckTeachers tbCheckTeachers) {
        Integer teacherCheckId = tbCheckTeachers.getTeacherCheckId();
        String checkContent = tbCheckTeachers.getCheckContent();
        String checkStatus = tbCheckTeachers.getCheckStatus();

        System.out.println(teacherCheckId+"      "+checkContent+"        "+checkStatus);
        int i=tbdao.changeTeacherCheck(teacherCheckId,checkContent,checkStatus);
        if (i>0){
            return new CommonResult(2000,"审核成功",null);
        }
        return new CommonResult(5000,"审核失败",null);
    }
}
